package com.wn.web;

import com.github.pagehelper.PageInfo;
import com.wn.common.pojo.Hotel;
import com.wn.common.pojo.PageParam;
import com.wn.common.pojo.Rsp;
import com.wn.service.HotelService;
import io.swagger.annotations.Api;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.util.StringUtils;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;


@RestControllerAdvice
@RequestMapping("hotel")
@Api(value = "酒店接口",description="酒店接口")
public class HotelController {
    @Autowired
    private HotelService hotelService;

    //查询所有
    @PostMapping("queryAll")
    public Rsp queryAll(@RequestBody PageParam<Hotel> hotelPageParam) {
        PageInfo<Hotel> hotelPageInfo = hotelService.queryAll(hotelPageParam);
        return Rsp.success(hotelPageInfo);
    }

    //根据主键查询
    @PostMapping("getHotelByid")
    public Rsp selectByPrimaryKey(@RequestBody Hotel record) {
        System.out.println("----------"+record);
       return hotelService.selectByPrimaryKey(record.getId());

    }

    //逻辑删除hotel数据
    @PostMapping("delete")
    public Rsp deleteById(@RequestBody Hotel hotel) {
        System.out.println("---------------------"+hotel);
        Rsp deletelogic = hotelService.deletelogic(hotel.getId());
        return deletelogic;
    }

    //更新数据
    @PostMapping("updateHotel")
    public Rsp updateAll(@RequestBody Hotel hotel){
        Rsp rsp = hotelService.updateAll(hotel);
        return rsp;
    }


    //增加数据
    @PostMapping("addHotel")
    public Rsp insertAll(@RequestBody @Valid Hotel hotel){
        return hotelService.insterAll(hotel);
    }


    //修改城市的状态
    @PostMapping("updateNewsinfo")
    public Rsp updateNewsinfo (@RequestBody @Valid Hotel hotel){

        Rsp rsp = hotelService.updateNewsinfo(hotel);

        return rsp;
    }
}
